<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>WinCC OA influxDB RestAPI For jQuery</title> 
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
</head>
<script>
$(document).ready(function() {  
  // 指定 InfluxDB 的 RestAPI 地址  
  var influxdbUrl = 'http://localhost:8086/query';  
  // 用户名和密码  
  var username = 'etm';  
  var password = 'etm#123';  
  
  // 构建查询语句,注意每行最后有个空格！
  // 注意：读出的数据都是UTC时间，请自行转换成LOCAL的时间（+8）
  var query = `SELECT time AS \"时间\", 
		first(\"original_value_float\") AS \"CUB_1_1_102_XF_TIT01消防泵房温度检测\" 
		FROM AI_FAST.AI_FAST 
		WHERE \"name\" = 'MEP:F1_CUB_1_1_102_XF_TIT01.STATE.VAL_IN.VALUE' 
		AND time >= '2023-07-15T02:00:00Z' 
		AND time <= now() - 1h
		GROUP BY time(1m) 
		FILL(previous) 
		ORDER BY time DESC 
		LIMIT 1000 
		SLIMIT 1`; 
  
   // 发送 GET 请求进行验证  
  $.ajax({  
    url: influxdbUrl,
    type: 'GET',  
    data: {  
      q: query,  
	  db:'winccoa',
      u: username,  
      p: password 
    },  
    success: function(response) {  
      // 处理成功返回的数据  
      console.log(response);  
    },  
    error: function(xhr, status, error) {  
      // 处理请求失败的情况  
      console.log('Error: ' + error);  
      console.log('query: ' + query);  
    }  
  });  
});
</script>
</html>
